using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using Acms.SqlDal;

namespace Acms.Bll
{
    public class Search : Post
    {
        private Search() : base() {}
        private Search(Hashtable table) : base(table) { }
        private Search(Hashtable table, List<Search> collection) : base(table, collection) { }
        public static Search CreateInstance()
        {
            return new Search();
        }

        private static Search Get(Hashtable table)
        {
            if(table != null)
            {
                return new Search(table);
            }
            else
            {
                return null;
            }
        }

        private static List<Search> Get(Hashtable[] tables)
        {
            List<Search> tmp = new List<Search>();
            if(tables != null)
            {
                foreach(Hashtable table in tables)
                {
                    tmp.Add(new Search(table, tmp));
                }
            }
            return tmp;
        }

        public static List<Search> GetAllByTopicAndSearchTerm(int topicId, string searchTerm, int startIndex, int maxRecords, ref int totalRecords)
        {
            SearchDal dal = new SearchDal();
            return Get(dal.GetAllByTopicAndSearchTerm(topicId, searchTerm, startIndex, maxRecords, ref totalRecords));

        }

        protected override void Load(Hashtable table)
        {
            base.Load(table);
            rank = (int)table[SearchDal.Fields.Rank];
        }

        private int rank;
        public int Rank
        {
            get { return rank; }
        }
    }
}
